package top.heliming.youyou.cart.config;

import java.security.PublicKey;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import top.heliming.youyou.util.RsaUtils;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/06/14 下午 8:43
 */
@ConfigurationProperties(prefix = "leyou.jwt")
public class JwtProperties {

  private String pubKeyPath;// 公钥

  private PublicKey publicKey; // 公钥

  private String cookieName;

  private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);

  @PostConstruct
  public void init(){
    try {
      // 获取公钥和私钥
      this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
    } catch (Exception e) {
      logger.error("初始化公钥失败！", e);
      throw new RuntimeException();
    }
  }

  public String getPubKeyPath() {
    return pubKeyPath;
  }

  public void setPubKeyPath(String pubKeyPath) {
    this.pubKeyPath = pubKeyPath;
  }

  public PublicKey getPublicKey() {
    return publicKey;
  }

  public void setPublicKey(PublicKey publicKey) {
    this.publicKey = publicKey;
  }

  public String getCookieName() {
    return cookieName;
  }

  public void setCookieName(String cookieName) {
    this.cookieName = cookieName;
  }
}

